package com.kede.app.domain;

import com.kede.app.converenum.*;
import com.kede.app.po.GoodTypePo;
import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.io.Serializable;

/**
* @description /
* @author Pr.li
* @date 2023-05-23
**/
@Entity
@Data
@Table(name="sy_leescore_goods")
@EntityListeners(AuditingEntityListener.class)
public class LeescoreGoods implements Serializable {
    /**
    * 商品ID
    */
    @ApiModelProperty(value = "商品ID")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    private Integer id;
    /**
    * 分类ID
    */
    @ApiModelProperty(value = "分类ID")
    @Column(name = "`category_id`")
    private Integer categoryId;
    /**
    * 商品标题
    */
    @ApiModelProperty(value = "商品标题")
    @Column(name = "`name`",nullable = false)
    @NotBlank
    private String name;
    /**
    * 出售模式:0=积分模式,1=货币模式,2=金钱+货币模式
    */
//    @ApiModelProperty(value = "出售模式:0=积分模式,1=货币模式,2=金钱+货币模式")
//    @Column(name = "`paytype`")
//    private Integer paytype;
    /**
    * 商品类型: 0=实物商品,1=虚拟商品,2=积分
    */
    @ApiModelProperty(value = "商品类型: 0=实物商品,1=虚拟商品,2=积分")
    @Column(name = "`type`")
    @Convert(converter = GoodTypeConverEnum.Converter.class)
    private GoodTypeConverEnum type ;
    /**
    * 商品状态:0=删除,1=仓库,2=上架
    */
    @ApiModelProperty(value = "商品状态:0=删除,1=仓库,2=上架")
    @Column(name = "`status`",nullable = false)
    @NotNull
    @Convert(converter = GoodStatusEnumConver.Converter.class)
    private GoodStatusEnumConver status;
    /**
    * 商品发布时间
    */
    @ApiModelProperty(value = "商品发布时间")
    @Column(name = "`createtime`")
    private Integer createtime;
    /**
    * 商品详情
    */
    @ApiModelProperty(value = "商品详情")
    @Column(name = "`body`",nullable = false)
    @NotBlank
    private String body;
    /**
    * 兑换规则
    */
    @ApiModelProperty(value = "兑换规则")
    @Column(name = "`rule`",nullable = false)
    @NotBlank
    private String rule;
    /**
    * 图片缩略图
    */
    @ApiModelProperty(value = "图片缩略图")
    @Column(name = "`thumb`",nullable = false)
    @NotBlank
    private String thumb;
    /**
    * 商品图集
    */
    @ApiModelProperty(value = "商品图集")
    @Column(name = "`pics`",nullable = false)
    @NotBlank
    private String pics;
    /**
    * 权重排序
    */
    @ApiModelProperty(value = "权重排序")
    @Column(name = "`weigh`")
    private Integer weigh;
    /**
    * 更新时间
    */
    @ApiModelProperty(value = "更新时间")
    @Column(name = "`updatetime`")
    private Integer updatetime;
    /**
    * 商品库存
    */
    @ApiModelProperty(value = "商品库存")
    @Column(name = "`stock`",nullable = false)
    @NotNull
    private Integer stock;
    /**
    * 所需积分
    */
    @ApiModelProperty(value = "所需积分")
    @Column(name = "`scoreprice`",nullable = false)
    @NotNull
    private BigDecimal scoreprice;
    /**
    * 开放时间
    */
    @ApiModelProperty(value = "开放时间")
    @Column(name = "`firsttime`")
    private Integer firsttime;
    /**
    * 结束时间
    */
    @ApiModelProperty(value = "结束时间")
    @Column(name = "`lasttime`")
    private Integer lasttime;
    /**
    * 价格
    */
    @ApiModelProperty(value = "价格")
    @Column(name = "`money`")
    private BigDecimal money;
    /**
    * 已兑换
    */
    @ApiModelProperty(value = "已兑换")
    @Column(name = "`usenum`")
    private Integer usenum = 0;
    /**
    * 推荐:index=首页,hot=热门,recommend=推荐,new=最新
    */
//    @ApiModelProperty(value = "推荐:index=首页,hot=热门,recommend=推荐,new=最新")
//    @Column(name = "`flag`")
//    @Convert(converter = ClassifConverEnum.Converter.class)
//    private ClassifConverEnum flag;
    /**
    * 限购数量
    */
    @ApiModelProperty(value = "限购数量")
    @Column(name = "`max_buy_number`")
    private Integer maxBuyNumber;
    /**
    * 商品分销: 0=不开启,1=开启
    */
    @ApiModelProperty(value = "商品分销: 0=不开启,1=开启")
    @Column(name = "`fenxiao_status`")
    @Convert(converter = FenxiaoStatusConverEnum.Converter.class)
    private FenxiaoStatusConverEnum fenxiaoStatus ;
    /**
    * 运费
    */
    @ApiModelProperty(value = "运费")
    @Column(name = "`express_price`")
    private BigDecimal expressPrice;

    @Column(name = "`source_channel`")
    @Convert(converter = SourceChannelConverEnum.Converter.class)
    private SourceChannelConverEnum sourceChannel;

    /**
     * 地区编码，区一级
     */
    @Column(name = "`adcode`")
    private Integer adcode;

    /**
     * 地区编码，市一级
     */
    @Column(name = "`citycode`")
    private Integer citycode;

    /**
     * 地区编码，省一级
     */
    @Column(name = "`provincecode`")
    private Integer provincecode;


//    @ApiModelProperty(value = "展示标记")
//    @Column(name = "`show_tag`")
//    private Integer showTag;

    @Transient
    private GoodTypePo[] goodtypes;


    public void copy(LeescoreGoods source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
